package com.cjk.foundation.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.glxn.qrgen.QRCode;
import net.glxn.qrgen.image.ImageType;

public class QRCodeUtil {

	private static final Logger LOGGER = LoggerFactory.getLogger(QRCodeUtil.class);
	
	public static void createQRCode(String content, String filePath, String fileName, ImageType imageType){
		try {
			File qrCodeFile = QRCode.from(content).withCharset("UTF-8").to(imageType).withSize(250, 250).file();
			File pictureFile = new File(filePath, fileName);
			IOUtils.copy(new FileInputStream(qrCodeFile), new FileOutputStream(pictureFile));
		} catch (Exception e) {
			LOGGER.error("二维码存储失败！文件名：{}", filePath + fileName, e);
		}
	}

}
